package com.example.config;

import javax.sql.DataSource;

import org.nutz.dao.Dao;
import org.nutz.dao.impl.NutDao;
import org.nutz.integration.spring.SpringDaoRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.example.config.interceptor.NutzDaoInterceptor;

@Configuration
public class NutzConfig {
	
	/**
	 * 同 Spring 事务整合
	 * @return
	 */
	@Bean
	public SpringDaoRunner springDaoRunner(){
		SpringDaoRunner daoRunner = new SpringDaoRunner();
		return daoRunner;
	}
	
	@Bean
	public Dao nutDao(DataSource dataSource,SpringDaoRunner springDaoRunner){
		NutDao nutDao = new NutDao();
		nutDao.setDataSource(dataSource);
		//同 Spring 事务整合,使用spring事物管理器
		nutDao.setRunner(springDaoRunner);
		return nutDao;
	}
	
	@Bean
	public NutzDaoInterceptor nutzDaoInterceptor(){
		return new NutzDaoInterceptor();
	}

}
